#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
inline int read()
{
    char c = getchar();
    int x = 0;
    bool flag = false;
    while(c < '0' || c > '9') c = getchar();
    while(c >= '0' && c <= '9')
    {
        x = (x << 3) + (x << 1) + int(c-'0');
        c = getchar();
    }
    return x;
}
int T;
int n,m,dis,maxv;
int d[N],v[N],a[N],p[N];
int car;
bool vis[N];
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    T = read();
    while(T--)
    {
        car = 0;
        n = read(); m = read(); dis = read(); maxv = read();
        for(int i = 1;i <= n;i++) d[i] = read(),v[i] = read(),a[i] = read();
        for(int i = 1;i <= m;i++) p[i] = read();
        int comparee = -1;
        for(int i = 1;i <= m;i++) comparee = max(comparee,p[i]);
        for(int i = 1;i <= n;i++)
        {
            if(v[i] > maxv && d[i] <= comparee)
                car++;
        }
        if(car == 0) printf("%d %d\n",car,m);
        else printf("%d %d\n",car,m-1);
    }
    return 0;
}
